<?php
/**
 * Created by PhpStorm.
 * User: zhangxinke
 * Date: 2019/6/1
 * Time: 11:09
 */

namespace app\api\controller;
use app\api\model\PassworkModel;

use think\Controller;
use think\Db;


class Password extends BaseController
{
    protected $uid;
    protected $userData;
    public function __construct()
    {
        parent::__construct();
      	header("Access-Control-Allow-Origin: *");
      	header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
        header('Access-Control-Allow-Headers:x-requested-with,content-type');
        $this->pwd = new PassworkModel();
    }
    public function AjaxReturn($code,$msg,$data=array())
    {

        $returnData=array(
            "code"=>$code
        );
        if($msg)
        {
            $returnData["message"]=$msg;
        }
        if(!empty($data))
        {
            $returnData["data"]=$data;
        }
        exit(json_encode($returnData));
    }
     /**修改登录密码**/
    public function pwdupdate(){
        $id=$this->uid;
        $pwdone=input('pwdone');
        $pwdtwo=input('pwdtwo');
        $oldpwd=input('oldpwd');
        if ($pwdone!=$pwdtwo){
            return $this->AjaxReturn('-1','密码不一致');
        }
        $user_list=$this->pwd->user_list($id);
        if (authcode($user_list['login_pwd'],'DECODE')!=$oldpwd){
            return $this->AjaxReturn('0','旧密码不正确');
        }
        $res=$this->pwd->pwdupdate($pwdtwo,$id);
        if(!empty($res)){
            return $this->AjaxReturn('1','修改成功');
        }else{
            return $this->AjaxReturn('0','绑定失败');
        }
    }
    //登录的忘记密码判断验证码
    public function forgetpwd(){
        $res=$this->pwd->forgetpwd();
         return json_encode($res);
    }
    //登录的忘记密码修改
    public function forgetpwds(){
        $phone = input('phone');
        $res=$this->pwd->forgetpwds($phone);
        if(!empty($res)){
            return $this->AjaxReturn('1','修改成功');
        }else{
            return $this->AjaxReturn('0','修改失败');
        }
    }
}